<template>
  <el-card class="box-card" style="margin-bottom:10px">
    <el-form :disabled="isDisable" :inline="true" class="demo-form-inline">
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option :label="c1.name" v-for="c1 in categoryStore.category1List" :key="c1.id" :value="c1.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option v-for="c2 in categoryStore.category2List" :label="c2.name" :value="c2.id" :key="c2.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option v-for="c3 in categoryStore.category3List" :label="c3.name" :value="c3.id" :key="c3.id" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: "CategorySeletor",
};
</script>

<script lang="ts" setup>
import { computed, onMounted, reactive } from "vue";
// 获取store中的数据，categoryListStore
import {useCategoryListStore} from '@/stores/categoryList'

// 获取对应的store对象
const categoryStore = useCategoryListStore()

defineProps(['isDisable'])
// 页面加载完就需要请求一级导航数据
onMounted(async()=>{
  categoryStore.getCategory1ListData()
})

// 使用计算属性精简ID
// 一级导航
const category1Id = computed({
  get(){
    return categoryStore.category1Id as number
  },
  set(val:number){
    //获取二级导航数据
    categoryStore.getCategory2ListData(val)
  }
})

// 二级导航
const category2Id = computed({
  get(){
    return categoryStore.category2Id  as number
  },
  set(val:number){
    //获取三级导航数据
    categoryStore.getCategoty3ListData(val)
  }
})
// 三级导航
const category3Id = computed({
  get(){
    return categoryStore.category3Id  as number
  },
  set(val:number){
   categoryStore.setCategory3Id(val)
  }
})
</script>

<style  scoped>
</style>